import React from 'react';
import { Typography } from '../../../Typography';
function fixPoint(point='', num) {
    const len = point.length;
    if (len === num) {
        return point;
    }
    if (len > num) {
        return point.substring(0, num);
    }
    return point + '0'.repeat(num - len);
}
function formatNum(num, point) {
    const numStr = `${num}`.split('.')[0];
    const resolveNum = +num;
   if (numStr.length < 6) {
        return num;
    }
    else if (numStr.length >= 6 && numStr.length <= 8) {
        const decimal = fixPoint(numStr.substring(numStr.length - 4, numStr.length - 4 + point), point);
        return parseInt(`${resolveNum / 10000}`) + '.' + decimal + '万';
    }
    else if (numStr.length > 8) {
        const decimal = fixPoint(numStr.substring(numStr.length - 8, numStr.length - 8 + point), point);
        return parseInt(`${resolveNum / 100000000}`) + '.' + decimal + '亿';
    }
}
/**
 * 数字文本组件，格式化数字
*/
export const NumText = (props) => {
    const { pre, num, suffix, point = 2, ...args } = props;
    return (<Typography {...args}>{pre && pre}{(num || num == 0) ? formatNum(num, point) : ''}{suffix && suffix}</Typography>);
};
export default NumText;
